package com.chen.serlvet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 向域中添加数据
 */
@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 向请求域中添加数据
        req.setAttribute("req", "reqMsg");
        // 向会话域中添加数据
        req.getSession().setAttribute("session", "sessionMsg");
        // 向应用的中添加数据
        getServletContext().setAttribute("application", "ApplicationMsg");
        // 请求域中的数据只能在本次请求或者请求转发的 service 方法中使用
        req.getRequestDispatcher("/servletC").forward(req, resp);
    }


}
